package com.xbai.spark.core.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * mapValues 算子
  * 作用：针对于 (K,V) 形式的类型只对 V 进行操作
  * 案例：创建一个pairRDD，并将value添加字符串"|||"
  *
  * @author xbai
  * @Date 2020/12/31
  */
object Spark22_MapValues {

  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("mapValues")
    val sc = new SparkContext(conf)

    val rdd: RDD[(Int, String)] = sc.parallelize(Array((1,"a"),(1,"d"),(2,"b"),(3,"c")))
    val mapValuesRDD: RDD[(Int, String)] = rdd.mapValues(_ + "|||")
    mapValuesRDD.collect().foreach(println)
  }
}
